<template>
  <div>
    <el-form ref="form" :model="intro" label-width="80px">
      <el-form-item label="新增类别">
        <el-input v-model="intro.category"  style="width: 217px;" placeholder="请输入新增类别名称"></el-input>
      </el-form-item>


      <el-form-item>
        <el-button type="primary" @click="onAdd">添加</el-button>
        <el-button @click="cancel">取消</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
import axios from "axios";

export default {
  name: "UserMemberAddView",
  data(){       //data:{}
    return {
      intro:{
        category:"",
        id:0,
      },

    }
  },

  methods:{
    onAdd(){
      //创建表格对象
      var formData = new FormData()
      for (const arr in this.intro) {
        formData.append(arr, this.intro[arr])
      }

      //请给我写一个确定添加的前置条件
      if(confirm("确定要添加吗")) {
        axios({
          url: "/api/classification/add",
          method: "post",
          data: formData,
          //添加请求头
          // headers: {"Content-Type": "multipart/form-data"}
          headers:{"Authorization":"Bearer "+this.$store.state.user.token}
        }).then(res => {
          console.log(res.data.code)
          if(res.data.code==1){
              this.$message({
                message: '添加成功',
                type:'success'
              });
              //返回分类表
              this.$router.push("/novel")
          }else {
            this.$message({
              message: res.data.message,
              type:'error'
            });
          }
          // if(res.data.code=403){
          //   this.$message({
          //     message: res.data.message,
          //     type:'error'
          //   });
          // }else {
          //   this.$message({
          //     message: '添加成功',
          //     type:'success'
          //   });
          //   //返回分类表
          //   this.$router.push("/novel")
          // }

        })
      }

        // axios.post("/api/user/add",formData)
        //     .then(res=>{
        //       this.$message({
        //         message: '添加成功',
        //         type:'success'
        //       });
        //       //返回医生信息表
        //       this.$router.push("/role")
        //     })
    },
    cancel(){
      this.$router.push("/novel/novelView")
    },
  }
}
</script>

<style scoped>

</style>
